package com.sky.controller.user;


import com.sky.result.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("userShopController")
@RequestMapping("/user/shop")
@Slf4j
public class ShopController {

    private static final String KEY = "SHOP_STATUS";
    private static final String SHOP_STATUS = "1";

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/status")
    @ApiOperation("获取店铺的营业状态")
    public Result<Integer> getStatus() {
        String status = (String) redisTemplate.opsForValue().get(KEY);
        if (status != null && status != ""){
            log.info("获取到店铺的营业状态：{}", SHOP_STATUS.equals(status) ? "营业中" : "打烊中");
            return Result.success(Integer.parseInt(status));
        }else{
            throw new RuntimeException("Redis中无法获取到店铺营业状态");
        }

    }
}
